package com.wss.merchant.configuration;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Controller;

import java.util.Date;

//自动添加时间

@Controller
public class MyMetaObjetctHandler implements MetaObjectHandler {
    @Override   //添加时
    public void insertFill(MetaObject metaObject) {
        String time = String.valueOf(new Date().getTime());
        Integer date = Integer.valueOf(time.substring(0, time.length() - 3));
        this.setFieldValByName("addtime",date,metaObject);

        this.setFieldValByName("status",1,metaObject);
        this.setFieldValByName("createTime",date,metaObject);
        this.setFieldValByName("updateTime",date,metaObject);
    }

    @Override   //更新数据
    public void updateFill(MetaObject metaObject) {
        String time = String.valueOf(new Date().getTime());
        Integer date = Integer.valueOf(time.substring(0, time.length() - 3));
        this.setFieldValByName("updateTime",date,metaObject);

    }
}
